# coding:utf-8
"""
"""
import os
from multiprocessing import Pool

def convertToDNA(param):
    data = open(param[0],"rb").read()
    strlen = len(data)
    strlen = strlen if strlen % 2 == 0 else strlen-1
    index = 0
    result = ""
    print "now process %s" % param[1]
    while index < strlen:
        if data[index:index+2] == "00":
            result += "A"
        elif data[index:index+2] == "11":
            result += "T"
        elif data[index:index+2] == "10":
            result += "C"
        elif data[index:index+2] == "01":
            result += "G"
        index += 2
    open(param[1], "wb").write(result)
    return True

def main():
    """
        主函数
    """
    root = os.getcwd()
    params = []
    for filepath in os.listdir(root+"/data/"):
        if os.path.isfile(root+"/data/"+filepath):
            path = root+"/data/"+filepath
            # fileData = open("")
            params.append((path, root+"/DNA/"+filepath))
    
    pool = Pool(5)
    pool.map(convertToDNA,params)


if __name__ == '__main__':
    main()

